﻿namespace Xmart.Expressions.DynamicPredicate;

public abstract class DynamicPredicateTestsBase
{
    protected IServiceProvider ServiceProvider { get; }
    protected IDynamicPredicateBuilder DynamicPredicateBuilder { get; }
    protected List<DynamicPredicateTestEntity> TestData { get; }
    public DynamicPredicateTestsBase()
    {
        IServiceCollection services = new ServiceCollection();
        services.AddDynamicPredicate();
        services.AddSingleton<IDynamicPredicateExtensions, TestDynamicPredicateExtensions>();
        ServiceProvider = services.BuildServiceProvider();
        DynamicPredicateBuilder = ServiceProvider.GetRequiredService<IDynamicPredicateBuilder>();
        TestData = new();
        for (byte i = 0; i < 10; i++)
        {
            var testData = new DynamicPredicateTestEntity
            {
                BoolValue = i % 2 == 0,
                ByteValue = (byte)(i + 1),
                SByteValue = (sbyte)(i + 2),
                ShortValue = (short)(i + 3),
                UShortValue = (ushort)(i + 4),
                IntValue = i + 5,
                UIntValue = (uint)(i + 6),
                LongValue = (long)(i + 7),
                ULongValue = (ulong)(i + 8),
                FloatValue = (float)(i + 9),
                DoubleValue = (double)(i + 10),
                DecimalValue = (decimal)(i + 11),
                DateTimeValue = new DateTime(2020, 1, 1 + i),
                StringValue = "S" + i,
                GuidValue = Guid.Parse("F" + (i + 1).ToString().PadLeft(31, '0')),
                EnumValue = (TestEnum)i,
                NullableValue = i,
                NullableDateTimeValue = i % 2 == 0 ? null : new DateTime(2020, 1, 1 + i),
                IntArrayValue = new[] { 10 + i, 20 + i, },
                IntListValue = new() { 30 + i,40 + i, },
                ItemListValue = new()
                {
                    new() { BoolValue= i % 2 == 0, IntValue = 50 + i },
                    new() { BoolValue= i % 2 != 0, IntValue = 60 + i },
                }
            };
            TestData.Add(testData);
        }
        TestData[9].StringValue = "";
        TestData[9].NullableValue = null;
    }
}
